package com.pure.common.clone;

/**
 * @description:
 * @date: 2022-09-23 13:18
 * @since 1.2.0
 **/
public class ShallowCopy {

    public static void main(String[] args) throws CloneNotSupportedException {

//        Food food = new Food("food", 10, "食物");
//        Food foodClone = (Food) food.clone();
//        foodClone.setName("foodClone");
//        // hashCode 不同，栈中指向内存区域的指针不同，在内存空间分别是独立的互不干扰，但这只是一次浅拷贝操作。
//        System.out.println("food :" + food + " hashCode :" + food.hashCode());
//        System.out.println("food clone :" + foodClone + " hashCode :" + foodClone.hashCode());

        FatherClass fatherClass = new FatherClass("father class");
        Milk milk = new Milk("milk", 350, "生牛乳", fatherClass);
        System.out.println("milk :" + milk + " hashCode :" + milk.hashCode());
        Milk milkClone = (Milk) milk.clone();
        System.out.println("milkClone :" + milkClone + " hashCode :" + milkClone.hashCode());

        System.out.println("(milk.fatherClass == milkClone.fatherClass) :" + (milk.fatherClass == milkClone.fatherClass));
        System.out.println("milk.fatherClass.hashCode :" + milk.fatherClass.hashCode() + " milkClone.fatherClass.hashCode :" + milkClone.fatherClass.hashCode());
    }
}
